#define _CRT_SECURE_NO_WARNINGS

#include "Date.h"

date& date::operator = (const date& d)
{
	_year = d._year;
	_month = d._month;
	_day = d._day;

	return *this;
}

bool date::operator == (const date& d)const
{
	return _year == d._year && _month == d._month && _day == d._day;
}
bool date::operator != (const date& d)const
{
	return !(*this == d);
}
bool date::operator < (const date& d)const
{
	if (_year < d._year)
	{
		return true;
	}
	else if (_year == d._year && _month < d._month)
	{
		return true;
	}
	else if (_year == d._year && _month == d._month && _day < d._day)
	{
		return true;
	}

	return false;
}
bool date::operator <= (const date& d)const
{
	return (*this == d) || (*this < d);
}
bool date::operator > (const date& d)const
{
	if (_year > d._year)
	{
		return true;
	}
	else if (_year == d._year && _month > d._month)
	{
		return true;
	}
	else if (_year == d._year && _month == d._month && _day > d._day)
	{
		return true;
	}

	return false;
}
bool date::operator >= (const date& d)const
{
	return (*this > d) || (*this == d);
}

date date::operator + (int day)
{
	date tmp(*this);
	tmp += day;
	return tmp;
}
date& date::operator += (int day)
{
	if (day < 0)
	{
		*this -= (-day);
		return *this;
	}

	_day += day;
	while (_day > GetMonthDay(_year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		_month++;
		if (_month == 13)
		{
			_year++;
			_month = 1;
		}
	}

	return *this;
}
date date::operator - (int day)
{
	date& tmp(*this);
	tmp -= day;
	return tmp;
}
date& date::operator -= (int day)
{
	if (day < 0)
	{
		*this += (-day);
		return *this;
	}

	_day -= day;
	while (_day <= 0)
	{
		_month--;
		if (_month == 0)
		{
			_year--;
			_month = 12;
		}
		_day += GetMonthDay(_year, _month);
	}

	return *this;
}

date& date::operator ++ ()
{
	(*this) += 1;
	return *this;
}
date date::operator ++ (int)
{
	date tmp(*this);
	*this += 1;
	return tmp;
}
date& date::operator -- ()
{
	*this -= 1;
	return *this;
}
date date::operator -- (int)
{
	date tmp(*this);
	*this -= 1;
	return tmp;
}

int date::operator - (const date& d)
{
	date max = *this;
	date min = d;
	int flag = 1;
	if (max < d)
	{
		max = d;
		min = *this;
		flag = -1;
	}

	int count = 0;
	while (max != min)
	{
		min++;
		count++;
	}

	return count * flag;
}